//回到顶部
    var backTop=document.getElementById("backTop"),
    topH,//滚动条距离顶部高度
    backTopSpeed,//滚动速度
    backTopTimer;//定时器
    backTop.addEventListener('click',function(){
        var backTopTimer = setInterval(function(){
            topH = document.documentElement.scrollTop || document.body.scrollTop;
            backTopSpeed = Math.floor(-topH/8);//取整
            if(topH>0){
                document.documentElement.scrollTop = document.body.scrollTop = topH+backTopSpeed;
            }else{
                clearInterval(backTopTimer);
            }
        },30);
    });
    var backTopTimer = setInterval(function(){
        topH = document.documentElement.scrollTop || document.body.scrollTop;
        backTopSpeed = Math.floor(-topH/8);//取整
        if(topH>2){
            gotop.style.display="block";
        }else{
            gotop.style.display="none";
        }
    })
var things = document.getElementById("things")
$(document).ready(function(){
    $.ajax({
        type:'get',
        url:"/getIndex",
        success:function(data){
            console.log(data);
            console.log(data.t.Brand[0][0].goodsId);
            console.log(data.t.Brand[0].length)
            for(i=0;i<9;i++){
                for(j=0;j<data.t.Brand[i].length;j++){
                    things.innerHTML+=
                        `<div class="thing">
                        <div class="photo"><img src="${data.t.Brand[i][j].goodsImg}" class="picture" name="${data.t.Brand[i][j].goodId}"></div>
                        <h4 class="function">${data.t.Brand[i][j].goodsName}</h4>
                        <p class="shop" name="${data.t.Brand[i][j].shopId}">${data.t.Brand[i][j].shopName}</p>
                        <p class="price">${data.t.Brand[i][j].goodsPrice}</p>
                        </div>`
                }
            };
            $(".function").each(function(){
                var str = $(this).html();
                var subStr = str.substring(0,25);
                var data = subStr+(str.length>25?'···':'');
                $(this).html(data);
            })
        },
        error:function(){
            alert("请求失败！")
        }
    })
})
/////////搜索框
var seeksth = document.getElementById("seeksth")
var seekit = document.getElementById("seekit")
var page = document.getElementById("page")
var things = document.getElementById("things")
seekit.onclick=function() {
    var sth = seeksth.value;
    console.log(sth)
    $.ajax({
        type: 'post',
        data: {
            goodsName: sth,
            pageNow: 1,
            pageSize: 15,
        },
        url: "/queryGoods",
        success: function (data) {
            if (sth == "") {
                alert("请输入要搜索的商品名！")
                return false;
            } else {
                console.log(data);
                things.innerHTML = "";
                console.log(data.goodsPage.list[0].goodsName);
                things.innerHTML +=
                    `<div class="thing">
                        <div class="photo"><img src="${data.goodsPage.list[0].goodsImg}" class="picture" name="${data.goodsPage.list[0].goodId}"></div>
                        <h4 class="function">${data.goodsPage.list[0].goodsName}</h4>
                        <p class="shop" name="${data.goodsPage.list[0].shopId}">${data.goodsPage.list[0].shopName}</p>
                        <p class="price">${data.goodsPage.list[0].goodsPrice}</p>
                        </div>`
                page.style.opacity = "0";
                $(".function").each(function(){
                    var str = $(this).html();
                    var subStr = str.substring(0,25);
                    var data = subStr+(str.length>25?'···':'');
                    $(this).html(data);
                })
            }
        },
        error: function () {
            console.log(error)
        }
    })
}
var top1 = document.getElementById("top1")
var top2 = document.getElementById("top2")
var top3 = document.getElementById("top3")
var top4 = document.getElementById("top4")
top1.onclick = function(){
    var fg = localStorage.getItem("key");
    console.log(fg)
    if(fg==2){
        window.location.href="/admin/login";
    }else if(fg==3){
        alert("管理员正在审核，请耐心等待！")
    }else if(fg==4){
        window.location.href="/Merchant/personShopCar"
    }else if(fg==1){
        var r=confirm("是否申请成为商家？");
        if (r==true) {
            content.style.display = "none";
            mone.style.display = "block";
        }else{
            window.location.href="/goodsDetail"
        }
    }else{
        alert("您还没有登录，请您先登录！")
        window.location.href = "/User/login";
    }
}
top2.onclick = function(){
    var fg = localStorage.getItem("key");
    console.log(fg)
    if(fg==0){
        alert("你还没有登录，请你先登录")
        window.location.href = "User/login";
    }else{
        window.location.href="/User/userInterface"
    }
}
top3.onclick = function(){
    window.location.href="/User/myCarPage"
}
top4.onclick = function () {
    window.location.href="/"
}